
(in-package :tutorial)



(defun get-all-actors-for-me ()
  (db.agraph.user::show-actors)
  )




(publish :path "/enter-new-actor"
    :content-type "text/html"
    :function 
    #'(lambda (req ent)
         (with-http-response (req ent)
           (with-http-body (req ent)
             (let ( 
                  ( the-name (text-request "name" req) )
                    ( the-description (text-request "description" req))
                    ; ( the-creation-date (text-request "creation-date" req))
                    ( the-comment (text-request "comment" req))
                    ( the-link (text-request "link" req))
                   

                   )
               (html 
                  (:html (:head (:title "Actors"))
                         (:body 
                          (:ul (:li "same as foaf:actor")
                               (:li "actor can be a singe human or a group or any other entity"  )
                               (:li ((:a :href "home") "Home") :br)
                               )
                          :p :hr :p
                          ((:form :action "create-new-actor")
                           (:table
                            (nice-text-input "name" the-name)
                           (nice-text-input "description" the-description)
                            ; (nice-text-input "creation-date" the-creation-date)
                            (nice-text-input "comment" the-comment)
                            (nice-text-input "link" the-link)
                             
                            (submit-button)
                            ) ; end table
                           ) ; end form
                         ); end body
                         )) ;end html
               ) ; end let
             ))))




(defun commit-actor ( the-name the-description the-creation-date the-comment the-link )
  (let* (
        ( the-resource-as-list (list ; 'res 'actor
                                     ; 'id the-id
                                     'name the-name
                                     'description the-description
                                     'creation-date the-creation-date
                                     'comment the-comment
                                     'link the-link
                                     ))
         (the-id (id-from-list the-resource-as-list) )
        )
    
    (gen-res::commit-resource-as-list-02 'actor the-id the-resource-as-list)
    the-id
    ))




(publish :path "/create-new-actor"
    :content-type "text/html"
    :function 
    #'(lambda (req ent)
         (with-http-response (req ent)
           (with-http-body (req ent)
             (let* ( 
                   ; (the-triples (cons '("ID" "Name" ) (get-all-actors-for-me) ))
                   ( the-name (text-request "name" req) )
                    ( the-description (text-request "description" req))
                    ; ( the-creation-date (text-request "creation-date" req))
                    ( the-comment (text-request "comment" req))
                   ( the-link (text-request "link" req))
                    ( the-creation-date (get-current-date-in-the-appropriate-format))
                    ( the-id (commit-actor the-name the-description the-creation-date the-comment the-link ) )
                   )
                ; ( commit-actor the-id the-name the-description the-creation-date the-comment the-link )

               (html 
                  (:html (:head (:title "Actors"))
                         (:body 
                          (:ul (:li "Here is the new actor that you created")
                              (:li ((:a :href "home") "Home") :br)
                               )
                          :p :hr :p
                          (make-table `( ("Parameter" "Value")
                                        ("ID" ,the-id)
                                        ("name" ,the-name)
                                        ("description" ,the-description)
                                        ("creation-date" ,the-creation-date)
                                        ("comment" ,the-comment)
                                        ("link" ,the-link))
                                        
                            ) ; end table
                         ); end body
                         )) ;end html
               ) ; end let
             ))))





(publish :path "/list-all-actors"
    :content-type "text/html"
    :function 
    #'(lambda (req ent)
         (with-http-response (req ent)
           (with-http-body (req ent)
             (let ( (the-triples (cons '("ID" "Name" ) (get-all-actors-for-me) )))
               (html 
                  (:html (:head (:title "Actors"))
                         (:body 
                          (:ul (:li "same as foaf:actor")
                               (:li "actor can be a singe human or a group or any other entity"  )
                               (:li "there are " (:princ-safe (- (length the-triples) 1)) " actors")
                               (:li ((:a :href "home") "Home") :br)
                               )
                                    :p :hr :p
                          
                          
                          (make-table the-triples) :p :hr
                          
                         
                         ); end body
                         )) ;end html
               ) ; end let
             ))))


